﻿using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace 餐饮管理系统
{
	/// <summary>
	/// MainWindow.xaml 的交互逻辑
	/// </summary>
    public partial class MainWindow : Window
    {
        private DatabaseConnect databaseConnect;
        public DatabaseConnect DatabaseConnect
        {
            get
            {
                return databaseConnect;
            }
        }
        public MainWindow()
        {
            this.InitializeComponent();

            //打开数据库，封装在了DatabaseConnect里，在整个运行中都是打开的
            databaseConnect = new DatabaseConnect();
            databaseConnect.Open();

            InitializeStarButtons();

            //装载具体数据，具体步骤写在对应的.cs文件中（StaffManagement.cs中）

            loadCenterItems();
            initFinance();
            initOrder();
            initOnlineOrder();
            initMealTable();
            loadStaffs();
            loadUsers();
            this.SizeToContent = SizeToContent.Manual;
            this.Hide();
            LoginWindow loginWindow = new LoginWindow(this);
            loginWindow.Show();
        }

        private void InitializeStarButtons()
        {
            InitializeStaffStarButtons();
            InitializeMealStarButtons();
        }

        private void CloseStoryboard_Completed(object sender, EventArgs e)
        {
            databaseConnect.Close();
            this.Close();
        }

        private void MinStoryboard_Completed(object sender, EventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void MinButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.WindowState = WindowState.Minimized;
        }

        private void StartStoryboard_Completed(object sender, EventArgs e)
        {
            Storyboard slideStoryboard = (Storyboard)this.FindResource("SlideStoryboard");
            slideStoryboard.Begin();
        }

        private void SupplierButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            hidePage();
            //setTable(false);
        }

        private void OnlineOrderButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            hidePage();
        }

        private void OrderButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            hidePage();
        }

        private void BranchButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            hidePage();
            //setTable(true);
        }
		
		private void RegisterButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	hidePage();
        }

        private void hidePage()
        {
            this.FendianPage.Visibility = Visibility.Hidden;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Hidden;
			this.ZhucePage.Visibility = Visibility.Hidden;
        }

        private void radioButton3_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            this.RenyuanShouyeGrid.Visibility = Visibility.Visible;
            this.RenyuanGrid.Visibility = Visibility.Hidden;
            this.CaiwuGrid.Visibility = Visibility.Hidden;
            this.DingdanGrid.Visibility = Visibility.Hidden;
        }

        private void radioButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.RenyuanShouyeGrid.Visibility = Visibility.Hidden;
            this.RenyuanGrid.Visibility = Visibility.Visible;
            this.CaiwuGrid.Visibility = Visibility.Hidden;
            this.DingdanGrid.Visibility = Visibility.Hidden;
        }

        private void radioButton1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.RenyuanShouyeGrid.Visibility = Visibility.Hidden;
            this.RenyuanGrid.Visibility = Visibility.Hidden;
            this.CaiwuGrid.Visibility = Visibility.Visible;
            this.DingdanGrid.Visibility = Visibility.Hidden;

        }

        private void radioButton2_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.RenyuanShouyeGrid.Visibility = Visibility.Hidden;
            this.RenyuanGrid.Visibility = Visibility.Hidden;
            this.CaiwuGrid.Visibility = Visibility.Hidden;
            this.DingdanGrid.Visibility = Visibility.Visible;

        }

        private void SlideStoryboard_Completed(object sender, EventArgs e)
        {
            this.FendianPage.Visibility = Visibility.Visible;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Hidden;
        }

        private void Fendian_SlideBackRightGrid_Completed(object sender, EventArgs e)
        {
            setTable(true);
            Storyboard Fendian_slideReturnRightGrid = (Storyboard)this.FindResource("Fendian_SlideReturnRightGrid");
            Fendian_slideReturnRightGrid.Begin();
        }

        private void Youhui_SlideRightGrid_Completed(object sender, EventArgs e)
        {
            this.FendianPage.Visibility = Visibility.Hidden;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Visible;

        }

        private void Wangshang_SlideRightGrid_Completed(object sender, EventArgs e)
        {
            this.FendianPage.Visibility = Visibility.Hidden;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Visible;
            this.YouhuiPage.Visibility = Visibility.Hidden;
            this.ZhucePage.Visibility = Visibility.Hidden;

        }

        private void Gongying_SlideBackRightGrid_Completed(object sender, EventArgs e)
        {
            setTable(false);
            Storyboard Gongying_slideReturnRightGrid = (Storyboard)this.FindResource("Gongying_SlideReturnRightGrid");
            Gongying_slideReturnRightGrid.Begin();
        }

        private void CloseButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.FendianPage.Visibility = Visibility.Hidden;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Hidden;
            this.ZhucePage.Visibility = Visibility.Hidden;
            Storyboard closeStoryboard = (Storyboard)this.FindResource("CloseStoryboard");
            closeStoryboard.Begin();
        }

        private void image1_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // TODO: Add event handler implementation here.
            this.DragMove();
        }

        private void image2_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // TODO: Add event handler implementation here.
            this.DragMove();
        }

        private void radioButton4_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            this.GongyingGrid.Visibility = Visibility.Hidden;
            this.GongyingShouyeGrid.Visibility = Visibility.Visible;
        }

        private void radioButton5_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            this.GongyingGrid.Visibility = Visibility.Visible;
            this.GongyingShouyeGrid.Visibility = Visibility.Hidden;
        }

        private void Fendian_SlideReturnRightGrid_Completed(object sender, EventArgs e)
        {
            this.FendianPage.Visibility = Visibility.Visible;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Hidden;
            this.ZhucePage.Visibility = Visibility.Hidden;
        }

        private void Gongying_SlideReturnRightGrid_Completed(object sender, EventArgs e)
        {
            this.FendianPage.Visibility = Visibility.Hidden;
            this.GongyingPage.Visibility = Visibility.Visible;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Hidden;
            this.ZhucePage.Visibility = Visibility.Hidden;
        }

        private void ZhecePage_SlideBack_Completed(object sender, EventArgs e)
        {
            this.FendianPage.Visibility = Visibility.Hidden;
            this.GongyingPage.Visibility = Visibility.Hidden;
            this.WangshangPage.Visibility = Visibility.Hidden;
            this.YouhuiPage.Visibility = Visibility.Hidden;
            this.ZhucePage.Visibility = Visibility.Visible;
        }

        private void MaxButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
			if(this.WindowState == WindowState.Normal){
				this.WindowState = WindowState.Maximized;
				this.max.Visibility = Visibility.Hidden;
				this.re.Visibility = Visibility.Visible;
			}else{
				this.WindowState = WindowState.Normal;
				this.max.Visibility = Visibility.Visible;
				this.re.Visibility = Visibility.Hidden;
			}
        }

        private void WangshangRadioButton_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.DianneiGrid.Visibility = Visibility.Hidden;
            this.DingdanListBox.Visibility = Visibility.Hidden;
            this.WangshangGrid.Visibility = Visibility.Visible;
            this.WangshangDingdanListBox.Visibility = Visibility.Visible;
            //listOnlineDate();

        }

        private void DianneiRadioButton_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            // 在此处添加事件处理程序实现。
            this.DianneiGrid.Visibility = Visibility.Visible;
            this.DingdanListBox.Visibility = Visibility.Visible;
            this.WangshangGrid.Visibility = Visibility.Hidden;
            this.WangshangDingdanListBox.Visibility = Visibility.Hidden;
            //listDate();
        }

    }
}